<?php
/**
 * List of constants and retrieval for Order Statuses, Payment Types and Others.
 * @author AngelaMisa 02/15/2015
 */
class Constant {
	// List Names                                                                                                                                                                                                                   
	const LIST_ORDER		= 'order';
	const LIST_PAYMENT	= 'payment';
	const LIST_SIZE			= 'size';
	const LIST_SHIPPING	= 'shipping';
	const LIST_TOPUP		= 'topup';

	// Order Status List in DB
	const ORDER_TOPUP									= 0;
	const ORDER_PROCESSING						= 1;
	const ORDER_ORDERED_FROM_SUPPLIER	= 2;
	const ORDER_RECEIVED								= 3;
	const ORDER_FOR_DELIVERY						= 4;
	const ORDER_DELIVERED							= 5;
	const ORDER_CANCELLED							= 6;
	const ORDER_BILLED									= 7;
	const ORDER_FORFEITED							= 8;
	
	// Payment Types in DB
	const PAYMENT_BANK_DEPOSIT			= 'bank_deposit';
	const PAYMENT_PAYPAL						= 'pp_standard';
	const PAYMENT_POINTS						= 'points';
	const PAYMENT_SALARY_DEDUCTION	= 'salary_deduction';
	
	//Top up Status List in DB 
	const TOPUP_NORMAL		= 0;
	const TOPUP_PENDING 	= 0;
	const TOPUP_FORCHECKING	= 1;
	const TOPUP_APPROVED 	= 2;
	const TOPUP_CANCEL 		= 3;
	const TOPUP_RETURNED	= 4;
	
	//Topp Status Action
	const TOPUP_CANCEL_ACTION			= 7;
	const TOPUP_PENDING_ACTION			= 2;
	const TOPUP_PROCESSING_ACTION	= 1;

	// Supply Chain - User Levels
	const USER_MANAGER	= 'manager';
	const USER_ASSOCIATE	= 'associate';

	// Size Codes
	const PROD_SMALL					= 1;
	const PROD_MEDIUM				= 2;
	const PROD_SIZEONE				= 3;
	const PROD_NDEL					= 4;
	const PROD_LARGE					= 7;
	const PROD_WELCOMEHOME	= 9;
	const PROD_FD						= 10;
	const PROD_CEBULARGE		= 11;
	const PROD_IMARFLEXSMALL	= 12;
	const PROD_IMARFLEXLARGE = 13;
	const PROD_CEBUSMALL		= 16;
	const PROD_XLARGE				= 17;

	// Modules Routes
	const COMMON_ROUTES = '/,dashboard,login,logout';
	
	// CRUD
	const CRUD_CREATE 	= 'create';
	const CRUD_READ 		= 'read';
	const CRUD_UPDATE	= 'update';
	const CRUD_DELETE	= 'delete';
	
	// Purchase Order Status List in DB
	const PO_PENDING		= 0;
	const PO_APPROVED	= 1; // This is same as received - geoff
	const PO_DENIED			= 2;
	
	// Is Voucher
	const IS_VOUCHER = 1;
	
	// Receive Voucher Statuses
	const VOUCHER_SENT = 1;
	const VOUCHER_RECEIVED = 2;
	
	// Purchase Order Shipping Address
	const PO_SHIPPING_ACOMMERCE	= 'ACOMMERCE';
	const PO_SHIPPING_HOME 				= 'HOME';
	const PO_SHIPPING_NODELIVERY	= 'NO DELIVERY';
		
	// Admin User
	const SUPER_USER = 'admin';
	
	// Download/Upload Type
	const FILE_DOWNLOAD 	= 0;
	const FILE_UPLOAD			= 0;
	const FILE_LIMIT				= 25;
	
	// OrderToSet Delivery Methods
	const DELIVERY_HOMEDELIVERY	= 'HOME DELIVERY';
	const DELIVERY_SUPPLIERPICKUP = 'SUPPLIER PICKUP';
	const DELIVERY_NODELIVERY			= 'NO DELIVERY';
	const DELIVERY_OFFICEPICKUP		= 'OFFICE PICKUP';
	
	/**
	 * Get CRUD.
	 * @author Aimon 02/23/2015
	 * @return array
	 */
	public static function getCRUD( $prettify = false ) {
		$crud = [
			self::CRUD_CREATE	=> 'create',
			self::CRUD_READ		=> 'read',
			self::CRUD_UPDATE	=> 'update',
			self::CRUD_DELETE 	=> 'delete'		
		];

		if ( $prettify ) {
			return array_map(function( $val ) {
				return ucwords(str_replace('_', ' ', $val));
			}, $crud);
		}

		return $crud;
	}

	/**
	 * Get User Levels.
	 * @author Aimon 02/23/2015
	 * @return array
	 */
	 public static function getUserLevels( $prettify = false ) {
		$user_levels = [
				self::USER_MANAGER => 'manager', 
				self::USER_ASSOCIATE => 'associate'
				];
				
		if ( $prettify ) {
			return array_map(function( $val ) {
				return ucwords(str_replace('_', ' ', $val));
			}, $user_levels);
		}	

		return $user_levels;
	}

	/**
	 * Get List names.
	 * @author AngelaMisa 02/15/2015
	 * @return array
	 */
	public static function getListNames( $prettify = false ) {
		$list = array(self::LIST_ORDER, self::LIST_PAYMENT, self::LIST_SIZE, self::LIST_TOPUP);

		return ($prettify) ? array_map('ucwords', $list) : $list;
	}

	/**
	 * Get Order Status List.
	 * @author AngelaMisa 02/15/2015
	 * @param $prettify - set statuses to title case.
	 * @return array
	 */
	public static function getOrderList( $prettify = false ) {
		$orders = array(
			self::ORDER_TOPUP 									=> 'top_up',
			self::ORDER_PROCESSING							=> 'processing',
			self::ORDER_ORDERED_FROM_SUPPLIER	=> 'ordered_from_supplier',
			self::ORDER_RECEIVED								=> 'received',
			self::ORDER_FOR_DELIVERY						=> 'for_delivery',
			self::ORDER_DELIVERED								=> 'delivered',
			self::ORDER_CANCELLED							=> 'cancelled',
			self::ORDER_BILLED									=> 'billed',
			self::ORDER_FORFEITED								=> 'forfeited',
		);

		if ( $prettify ) {
			return array_map(function( $val ) {
				return ucwords(str_replace('_', ' ', $val));
			}, $orders);
		}

		return $orders;
	}

	/**
	 * Get Size List.
	 * @author AngelaMisa 02/23/2015
	 * @param $prettify - set statuses to title case.
	 * @return array
	 */
	public static function getSizeList( $prettify = false ) {
		$sizes = array(
			self::PROD_SMALL					=> 'small',
			self::PROD_MEDIUM					=> 'medium',
			self::PROD_SIZEONE 				=> 'size one',
			self::PROD_NDEL						=> 'no delivery',
			self::PROD_LARGE					=> 'large',
			self::PROD_WELCOMEHOME	=> 'welcome home',
			self::PROD_FD							=> 'healthy foodie',
			self::PROD_CEBULARGE			=> 'cebu large',
			self::PROD_IMARFLEXSMALL	=> 'imarflex small',
			self::PROD_IMARFLEXLARGE	=> 'imarflex large',
			self::PROD_CEBUSMALL			=> 'cebu small',
			self::PROD_XLARGE					=> 'extra large'
		);

		if ( $prettify ) {
			return array_map(function( $val ) {
				return ucwords(str_replace('_', ' ', $val));
			}, $sizes);
		}

		return $sizes;
	}
	
	/**
	 * Get P.O. Shipping List.
	 * @author AngelaMisa 03/08/2015
	 * @param $prettify - set statuses to title case.
	 * @return array
	 */
	public static function getShippingList( $prettify = false ) {
		$shippings = array(
			self::PO_SHIPPING_HOME				=> 'home',
			self::PO_SHIPPING_ACOMMERCE	=> 'acommerce',
			self::PO_SHIPPING_NODELIVERY	=> 'no_delivery'
		);
	
		if ( $prettify ) {
			return array_map(function( $val ) {
				return ucwords(str_replace('_', ' ', $val));
			}, $shippings);
		}
	
		return $shippings;
	}

	/**
	 * Get Purchase Order Status List.
	 * @author AngelaMisa 02/23/2015
	 * @param $prettify - set statuses to title case.
	 * @return array
	 */
	public static function getPoList( $prettify = false ) {
		$pos = array(
			self::PO_PENDING	=> 'pending',
			self::PO_APPROVED	=> 'approved',
			self::PO_DENIED		=> 'denied'
		);
	
		if ( $prettify ) {
			return array_map(function( $val ) {
				return ucwords(str_replace('_', ' ', $val));
			}, $pos);
		}
	
		return $pos;
	}

	/**
	 * Get Payment Types List.
 	 * @author AngelaMisa 02/15/2015
	 * @param $prettify
	 * @return array
	 */
	public static function getPaymentList( $prettify = false ) {
		$payments = array(
			self::PAYMENT_PAYPAL						=> 'paypal',
			self::PAYMENT_BANK_DEPOSIT			=> 'bank_deposit',
			self::PAYMENT_POINTS						=> 'points',
			self::PAYMENT_SALARY_DEDUCTION	=> 'salary_deduction'
		);

		if ( $prettify ) {
			return array_map(function( $val ) {
				return ucwords(str_replace('_', ' ', $val));
			}, $payments);
		}

		return $payments;
	}
	
	/**
	 * Get Top-up Status List.
	 * @author AngelaMisa 04/08/2015 12:12AM
	 * @param $prettify
	 * @return array
	 */
	public static function getTopupList( $prettify = false ) {
		$topups = array(
			self::TOPUP_PENDING				=> 'pending',
			self::TOPUP_FORCHECKING	=> 'for_checking',
			self::TOPUP_APPROVED			=> 'approved',
			self::TOPUP_CANCEL				=> 'rejected',
			self::TOPUP_RETURNED			=> 'returned'
		);
	
		if ( $prettify ) {
			return array_map(function( $val ) {
				return ucwords(str_replace('_', ' ', $val));
			}, $topups);
		}
	
		return $topups;
	}

	/**
	 * Get Name in List by its ID.
	 * @author AngelaMisa 02/15/2015
	 * @param $type, $id, $prettify
	 * @return null | string
	 */
	public static function getName( $list = '', $id = null, $prettify = false ) {
		$id = strlen(trim($id)) ? trim($id) : null;

		// has invalid list and null ID? end
		if ( !self::isValidList( $list ) || is_null($id) ) return null;

		$get_list_fn = 'get' . ucwords($list) . 'List';
		$get_list = self::$get_list_fn( $prettify );

		// get name in list
		return array_key_exists($id, $get_list) ? $get_list[$id] : null;
	}

	/**
	 * Get ID in List by its Name.
	 * @author AngelaMisa 02/15/2015
	 * @param $type, $id
	 * @return mixed
	 */
	public static function getId( $list = '', $name = '' ) {
		$name = trim($name);

		// has invalid list and name? end
		if ( !self::isValidList( $list ) || empty($name) ) return null;

		$get_list_fn = 'get' . ucwords($list) . 'List';

		// get id in list
		if ( $id = array_search($name, self::$get_list_fn()) !== false ) return $id;

		return null;
	}

	/**
	 * Check if List indicated exists.
	 * @author AngelaMisa 02/15/2015
	 * @param $name
	 * @return bool
	 */
	public static function isValidList( $name = '' ) {
		return ( in_array(strtolower(trim($name)), self::getListNames()) );
	}

	/**
	 * Get List by name indicated.
	 * @author AngelaMisa 02/15/2015
	 * @param $name, $prettify
	 * @return array
	 */
	public static function getList( $name = '', $prettify = false ) {
		$name = strtolower(trim($name));
		$list_fn = 'get' . ucwords($name) . 'List';

		return ( self::isValidList($name) ) ? self::$list_fn( $prettify ) : array();
	}
}